const mongoose = require('mongoose')
const { dbUrl } = require('../config/config.default')
mongoose.connect(dbUrl, {
    useNewUrlParser: true,
    useUnifiedTopology: true
})

const db = mongoose.connection

// 当连接失败的时候
db.on('error', err => {
    console.log('数据库连接失败', err);
})

// 当连接成功的时候
db.once('open', function () {
    console.log('数据库连接成功');
})

// 组织导出模型类
module.exports = {
    User: mongoose.model('User', require('./user')),
    Sheet: mongoose.model('Sheet', require('./sheet')),
    FileFolder: mongoose.model('FileFolder', require('./fileFolder')),
    Message: mongoose.model('Message', require('./message'))
}